package stream._01introduction;

import stream.bean.Student;
import stream.bean.StudentList;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/*
我们要对这个学生列表进行处理：得到来自北京的同学，并且高度最高的三个同学
 */
public class Demo {
    public static void main(String[] args) {
        List<Student> studentList = new StudentList().studentList;
        //System.out.println(studentList);

        //从数据源中找到北京的同学
        ArrayList<Student> students = new ArrayList<>();
        for (Student student : studentList) {
            if(student.getAddress() == Student.Address.BJ) {
                students.add(student);
            }
        }
        //所有北京的同学
        System.out.println(students);
        System.out.println(students.size());

        Collections.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.getHeight() - o1.getHeight();
            }
        });
        Student student1 = students.get(0);
        Student student2 = students.get(1);
        Student student3 = students.get(2);
        System.out.println("student1 = " + student1);
        System.out.println("student2 = " + student2);
        System.out.println("student3 = " + student3);

    }
}
